// index.ts

import { AppContext } from "../../app.context";
import { AppNotify, NotifyType } from "../../app.notify";
import { AudioFrequencyInfo } from "../../mode/audioFrequency";
import { AudioFrequencyService } from "../../services/audioFrequency.server";

Page({
  data: {
    videoList: <AudioFrequencyInfo[]>[],
    type: 'audio',
    showShare: false,

    showComment: false,
    
  },

  
  onLoad() {
    console.log('开启 index 页面 - onLoad');
    /** 收到通知（监听通知的置于最开始） */
    AppNotify.instance.addListener(NotifyType.Login, this.initData, this);
  },

  onShow() {
    // const videoList = AppContext.instance.audioFrequency.data;
    // console.log(videoList);
    // this.setData({ videoList });
    /** 发一条通知 */
    AppContext.instance.setTabbarActive(0)
    this.getTabBar().init();
  },

  /** 处理接收通知的方法 ：opt: NotifyOption, msg: string*/
  initData(): void {
    console.log('Login 通知--------');
    const that = this;
    AudioFrequencyService.instance.list().then(() => {
      const videoList = AppContext.instance.resources.audioFrequency;
      console.log(videoList);
      that.setData({ videoList });
    });
    const width = wx.getSystemInfoSync().windowWidth;
    const height = wx.getSystemInfoSync().windowHeight;
    console.log(width, height);

    const query = this.createSelectorQuery()
    query.select('#tabbar').boundingClientRect()
    query.selectViewport().scrollOffset()
    query.exec(function (res) {
      console.log(res);
    })
  },

  onResize(options) {
    console.log('页面参数', options);
  },
  onShareAppMessage() {
    return {
      title: '流行因乐-年轻人聚集地',
      desc: '',
      path: `/pages/index/index`,
      imageUrl: 'cloud://cloud1-6gniy62z975284f8.636c-cloud1-6gniy62z975284f8-1305217646/assets/image/jpg/lequ.jpg',
      success() { },
      fail() { },
      complete() { },
    };
  },


})
